home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / database / blt2rx_o.zip / SCRIPTS.ZIP / 03CRI.CMD < prev    next >
OS/2 REXX Batch file  |  1996-08-05  |  12KB  |  299 lines

  1. /* 03 - Create index example for Bullet/REXX */
  2. /* 3-Aug-96
  3.    Calls made in this example:
  4.    - blt_Init()
  5.    - blt_DeleteFileDos()   [to delete test-generated files]
  6.    - blt_CreateData()
  7.    - blt_OpenData()        [file-level locks used]
  8.    - blt_CreateIndex()
  9.    - blt_OpenIndex()
  10.    - blt_FlushIndexHeader()
  11.    - blt_ReadIndexHeader()
  12.    - blt_CopyIndexHeader()
  13.    - blt_ZapIndexHeader()
  14.    - blt_StatIndex()
  15.    - blt_CloseIndex()
  16.    - blt_CloseData()
  17.    - blt_Exit()
  18. */
  19.  
  20. /* Typically, each test routine's arg pack (blt_IP., etc.) is set to NOVALUE */
  21. /* so that any unset variables can easily be identified.  In actual use, */
  22. /* this would not be necessary since often arg pack values are already setup */
  23. /* for multiple calls, where blt_?P.variable is already properly set up */
  24.  
  25.  say "Example: 03cri.cmd  (recommend output be redirected to a file)"
  26.  
  27.  call RxFuncAdd 'BulletLoadFuncs', 'BREXXI2', 'BulletLoadFuncs'
  28.  call BulletLoadFuncs
  29.  
  30.  /* in case Bullet/REXX is still active, close it out */
  31.  
  32.  rez = blt_Exit()
  33.  
  34.  say
  35.  say "calling blt_Init()"
  36.  blt_IP.=NOVALUE
  37.  blt_IP.JFTsize=5       /* must be 5 */
  38.  rez = blt_Init()       /* init Bullet/REXX */
  39.  say " blt_IP.func is" blt_IP.func
  40.  say " blt_IP.stat is" blt_IP.stat  /* rez same as stat except for xactions */
  41.  if rez = 0 then do
  42.  
  43.     say " blt_IP.versionDOS is" blt_IP.versionDOS
  44.     say " blt_IP.versionOS is" blt_IP.versionOS
  45.     say " blt_IP.versionBullet is" blt_IP.versionBullet
  46.     /* say " blt_IP.exitPtr is" blt_IP.exitPtr */
  47.  
  48.     say
  49.     say "calling blt_DeleteFileDos() x4 (03CRI.DB?, 03CRI.IX3 O3CRIcpy.IX3)"
  50.     blt_DFP.=NOVALUE
  51.     blt_DFP.filename = "03CRI.DBF"
  52.     rez = blt_DeleteFileDos();
  53.     say " blt_DFP.func is" blt_DFP.func
  54.     say " blt_DFP.stat is" blt_DFP.stat "(03CRI.DBF) [stat=2, file not found, is possible]"
  55.  
  56.     blt_DFP.=NOVALUE
  57.     blt_DFP.filename = "03CRI.DBT"  /* may use QuerySysVars for memo .EXT */
  58.     rez = blt_DeleteFileDos();
  59.     say " blt_DFP.stat is" blt_DFP.stat "(03CRI.DBT)"
  60.  
  61.     blt_DFP.=NOVALUE
  62.     blt_DFP.filename = "03CRI.IX3"
  63.     rez = blt_DeleteFileDos();
  64.     say " blt_DFP.stat is" blt_DFP.stat "(03CRI.IX3)"
  65.  
  66.     blt_DFP.=NOVALUE
  67.     blt_DFP.filename = "03CRIcpy.IX3"   /* from CopyIndexHeader() */
  68.     rez = blt_DeleteFileDos();
  69.     say " blt_DFP.stat is" blt_DFP.stat "(03CRIcpy.IX3)"
  70.  
  71.     say
  72.     say "calling blt_CreateData()"
  73.     blt_CDP.=NOVALUE
  74.     blt_CDP.filename = "03CRI.DBF"
  75.     blt_CDP.noFields = 3
  76.     blt_CDP.FD.1.fieldName = "SSN"
  77.     blt_CDP.FD.1.fieldType = "N"
  78.     blt_CDP.FD.1.fieldLen = 9
  79.     blt_CDP.FD.1.fieldDC = 0
  80.     blt_CDP.FD.2.fieldName = "NAME"
  81.     blt_CDP.FD.2.fieldType = "C"
  82.     blt_CDP.FD.2.fieldLen = 10
  83.     blt_CDP.FD.2.fieldDC = 0
  84.     blt_CDP.FD.3.fieldName = "ADDR"
  85.     blt_CDP.FD.3.fieldType = "M"
  86.     blt_CDP.FD.3.fieldLen = 10
  87.     blt_CDP.FD.3.fieldDC = 0
  88.     blt_CDP.fileID = 139        /* memo, too  (139 is 0x8B [hex]) */
  89.     rez = blt_CreateData()      /* create data files: DBF and DBT */
  90.     say " blt_CDP.func is" blt_CDP.func
  91.     say " blt_CDP.stat is" blt_CDP.stat
  92.  
  93.     if rez = 0 then do
  94.        say
  95.        say "calling blt_OpenData()"
  96.        blt_OP.=NOVALUE
  97.        blt_OP.filename = blt_CDP.filename
  98.        blt_OP.asMode = 18       /* 18 is 0x0012 [hex] DENYRW, R/W */
  99.        rez = blt_OpenData()     /* see blt_Lock() for range locking */
  100.        say " blt_OP.func is" blt_OP.func
  101.        say " blt_OP.stat is" blt_OP.stat
  102.  
  103.        /* so far, similar to 02CRD.CMD */
  104.        /* must have data DBF open before creating index for it */
  105.  
  106.        dataID = 0       /* since two opens are done, cannot keep both handles */
  107.        indexID = 0      /* in the same blt_OP.handle var, so do this */
  108.  
  109.        if rez = 0 then do
  110.           dataID = blt_OP.handle
  111.           say " blt_OP.handle is" dataID
  112.           say
  113.           say "calling blt_CreateIndex()"
  114.           blt_CIP.=NOVALUE
  115.           blt_CIP.filename = "03CRI.IX3"
  116.           blt_CIP.keyExp = "SSN"        /* index is on entire SSN field */
  117.           blt_CIP.xbLink = dataID       /* blt_OP.handle from DBF open above */
  118.           blt_CIP.sortFunction = 1      /* ASCII sort, dups -not- allowed */
  119.           blt_CIP.codePage = 0
  120.           blt_CIP.countryCode = 0
  121.           blt_CIP.collateTable = ""     /* 0-len string for default, else 256-char table of weights */
  122.           blt_CIP.nodeSize = 512
  123.           rez = blt_CreateIndex()
  124.           say " blt_CIP.func is" blt_CIP.func
  125.           say " blt_CIP.stat is" blt_CIP.stat
  126.  
  127.           if rez = 0 then do
  128.              say
  129.              say "calling blt_OpenIndex()"
  130.              blt_OP.=NOVALUE
  131.              blt_OP.filename = blt_CIP.filename
  132.              blt_OP.asMode = 18
  133.  
  134.              /* index open requires blt_OP.xbLink set to DBF handle */
  135.              /* whereas .xbLink is not used in a data open */
  136.  
  137.              blt_OP.xbLink = dataID
  138.              rez = blt_Openindex()
  139.              say " blt_OP.func is" blt_OP.func
  140.              say " blt_OP.stat is" blt_OP.stat
  141.  
  142.              if rez = 0 then do
  143.                 indexID = blt_OP.handle
  144.                 say " blt_OP.handle is" indexID
  145.                 blt_HP.=NOVALUE
  146.                 blt_HP.handle = indexID
  147.                 say
  148.                 say "calling blt_FlushIndexHeader()"  /* purely for demo purpose */
  149.                 rez = blt_FlushIndexHeader()
  150.                 say " blt_HP.func is" blt_HP.func
  151.                 say " blt_HP.stat is" blt_HP.stat
  152.  
  153.                 if rez = 0 then do
  154.                    blt_HP.=NOVALUE
  155.                    blt_HP.handle = indexID
  156.                    say
  157.                    say "calling blt_ReadIndexHeader()"  /* purely for demo purpose */
  158.                    rez = blt_ReadIndexHeader()
  159.                    say " blt_HP.func is" blt_HP.func
  160.                    say " blt_HP.stat is" blt_HP.stat
  161.  
  162.                    if rez = 0 then do
  163.                       blt_CP.=NOVALUE
  164.                       blt_CP.handle = indexID
  165.                       blt_CP.filename = "03CRIcpy.IX3"
  166.                       say
  167.                       say "calling blt_CopyIndexHeader()"  /* purely for demo purpose */
  168.                       rez = blt_CopyIndexHeader()
  169.                       say " blt_CP.func is" blt_CP.func
  170.                       say " blt_CP.stat is" blt_CP.stat
  171.  
  172.                       if rez = 0 then do
  173.                          blt_HP.=NOVALUE
  174.                          blt_HP.handle = indexID        /* zaps .IX3 */
  175.                          say
  176.                          say "calling blt_ZapIndexHeader()"  /* purely for demo purpose */
  177.                          rez = blt_ZapIndexHeader()
  178.                          say " blt_HP.func is" blt_HP.func
  179.                          say " blt_HP.stat is" blt_HP.stat
  180.  
  181.                          if rez = 0 then do
  182.                             say
  183.                             say "calling blt_StatIndex()"
  184.                             blt_SIP.=NOVALUE
  185.                             blt_SIP.handle = indexID
  186.                             rez = blt_StatIndex()
  187.                             say " blt_SIP.func is" blt_SIP.func
  188.                             say " blt_SIP.stat is" blt_SIP.stat
  189.                             if rez = 0 then do
  190.  
  191.                                say " blt_SIP.handle is" blt_SIP.handle
  192.                                say " blt_SIP.fileType is" blt_SIP.fileType
  193.                                say " blt_SIP.flags is" blt_SIP.flags
  194.                                say " blt_SIP.progress is" blt_SIP.progress
  195.                                say " blt_SIP.morePtr is" blt_SIP.morePtr
  196.                                say " blt_SIP.xbLink is" blt_SIP.xbLink
  197.                                say " blt_SIP.asMode is" blt_SIP.asMode
  198.                                say " blt_SIP.filename is '"blt_SIP.filename"'"
  199.                                say " blt_SIP.fileID is '"blt_SIP.fileID"'"
  200.                                say " blt_SIP.keyExp is" "'"blt_SIP.keyExp"'"
  201.                                say " blt_SIP.keys is" blt_SIP.keys
  202.                                say " blt_SIP.keyLength is" blt_SIP.keyLength
  203.                                say " blt_SIP.keyRecNo is" blt_SIP.keyRecNo
  204.                                say " blt_SIP.key is '"blt_SIP.key"'"
  205.                                say " blt_SIP.herePtr is" blt_SIP.herePtr
  206.                                say " blt_SIP.codePage is" blt_SIP.codePage
  207.                                say " blt_SIP.countryCode is" blt_SIP.countryCode
  208.                                /* will be null-string, be aware that if was not default */
  209.                                /* many of the table bytes are not printable characters */
  210.                                say " blt_SIP.collateTable is '"blt_SIP.collatetable"'"
  211.                                say " blt_SIP.nodeSize is" blt_SIP.nodeSize
  212.                                dupsFlag = blt_SIP.sortFunction % 65536
  213.                                sortFunc = blt_SIP.sortFunction - (dupsFlag * 65536)
  214.                                say " blt_SIP.sortFunction is" blt_SIP.sortFunction
  215.                                say "    dups allowed flag is" dupsFlag
  216.                                say "        sort function is" sortFunc
  217.                                say " blt_SIP.lockCount is" blt_SIP.lockCount
  218.                             end
  219.                             else do
  220.                                say "* ERROR * blt_StatIndex()"
  221.                             end
  222.  
  223.                          end
  224.                          else do
  225.                             say "* ERROR * blt_ZapIndexHeader()"
  226.                          end
  227.  
  228.                       end
  229.                       else do
  230.                          say "* ERROR * blt_CopyIndexHeader()"
  231.                       end
  232.  
  233.                    end
  234.                    else do
  235.                      say "* ERROR * blt_ReadIndexHeader()"
  236.                    end
  237.  
  238.                 end
  239.                 else do
  240.                    say "* ERROR * blt_FlushIndexHeader()"
  241.                 end
  242.  
  243.                 /* if open, it's a good idea to close it (blt_Exit() will if not) */
  244.  
  245.                 blt_HP.=NOVALUE
  246.                 blt_HP.handle = indexID
  247.                 say
  248.                 say "calling blt_CloseIndex()"
  249.                 rez = blt_CloseIndex()
  250.                 say " blt_HP.func is" blt_HP.func
  251.                 say " blt_HP.stat is" blt_HP.stat
  252.  
  253.              end
  254.              else do
  255.                 say "* ERROR * blt_OpenIndexHeader()"
  256.              end
  257.  
  258.           end
  259.           else do
  260.              say "* ERROR * blt_CreateIndex()"
  261.           end
  262.  
  263.           /* if open, it's a good idea to close it (blt_Exit() will if not) */
  264.  
  265.           blt_HP.=NOVALUE
  266.           blt_HP.handle = dataID
  267.           say
  268.           say "calling blt_CloseData()"
  269.           rez = blt_CloseData()
  270.           say " blt_HP.func is" blt_HP.func
  271.           say " blt_HP.stat is" blt_HP.stat
  272.  
  273.        end
  274.        else do
  275.           say "* ERROR * blt_OpenData()"
  276.        end
  277.  
  278.     end
  279.     else do
  280.        say
  281.        say "* ERROR * blt_CreateData()"
  282.     end
  283.  
  284.     say
  285.     say "calling blt_Exit()"
  286.     blt_EP.=NOVALUE
  287.     rez = blt_Exit()
  288.     say " blt_EP.func is" blt_EP.func
  289.     say " blt_EP.stat is" blt_EP.stat
  290.     say " blt_EP.rxAllocsLeft is" blt_EP.rxAllocsLeft
  291.  end
  292.  else do
  293.     say
  294.     say "* ERROR * blt_Init()"
  295.  end
  296.  
  297.  call BulletDropFuncs
  298.  exit 0
  299.